#!/usr/bin/env python
# coding: utf-8

# In[2]:


import pandas as pd
import matplotlib.pyplot as plt
import numpy as np


# In[6]:


df = pd.read_csv('/Users/a/Desktop/log.txt',header = None)


# In[7]:


df.head()


# In[8]:


df = pd.read_csv('/Users/a/Desktop/log.txt',header = None,sep='\t')
df.head()


# In[9]:


df.columns = ['id','api','count','res_time_sum','res_time_min','res_time_max','res_time_avg','interval','created_time']
df.head(2)


# In[10]:


df.sample(5)


# In[11]:


df.shape


# In[12]:


df.info()


# In[13]:


df['api'].describe()


# In[14]:


df = df.drop('api',axis = 1)
df.head(2)


# In[15]:


df.info()


# In[16]:


df['created_time'].describe()


# In[17]:


df.index


# In[18]:


df.info()


# In[20]:


df.index = df['created_time']


# In[21]:


df.index = pd.to_datetime(df.created_time)


# In[22]:


df.index


# In[23]:


df['2019-5-1']


# In[24]:


df.interval.describe()


# In[25]:


df.interval.unique()


# In[26]:


df = df.drop(['id','interval'],axis = 1)
df.head()


# In[28]:


df.info()


# In[29]:


df.describe()


# In[30]:


df['count'].hist()
plt.show()


# In[31]:


df['count'].hist(bins=30)
plt.show()


# In[32]:


df['2019-5-1']['count'].plot()
plt.show()


# In[33]:


df2 = df['2019-5-1']


# In[34]:


df2=df2[['count']].resample('1H').mean()


# In[35]:


df2


# In[36]:


df2['count'].plot()
plt.show()


# In[40]:


plt.figure(figsize=(10,3))
df2['count'].plot(kind = 'bar')
plt.xticks(rotation = 90)
plt.show()


# In[41]:


df['2019-5-1'][['res_time_sum','res_time_min','res_time_max','res_time_avg']].plot()
plt.show()


# In[42]:


data = df['2019-5-1'].resample('20T').mean()
data[['res_time_sum','res_time_min','res_time_max','res_time_avg']].plot()
plt.show()


# In[43]:


df['2019-5-1':'2019-5-10']['count'].plot()


# In[44]:


df['2019-5-2'].index.weekday


# In[45]:


df['weekday']=df.index.weekday
df.head(2)


# In[46]:


df['weekend'] = df['weekday'].isin({5,6})
df.head()


# In[47]:


df.groupby('weekend')['count'].mean()


# In[48]:


df.groupby(['weekend',df.index.hour])['count'].mean()


# In[52]:


df.groupby(['weekend',df.index.hour])['count'].mean().unstack(level = 0).plot()
plt.show()


# In[ ]:




